package com.cn.整合.Spring;

import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

/**
 * @author: dlr
 * @data: 2019/8/20 22:32
 * @desc: Spring整合MQ生产者
 */
public class SpringMQ_Producer {

    public static void main(String[] args) {

        ApplicationContext ctx=new ClassPathXmlApplicationContext("application.xml");

        JmsTemplate jmsTemplate=(JmsTemplate)ctx.getBean("jmsTemplate");

        jmsTemplate.send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                TextMessage message=session.createTextMessage("Spring整合MQ发送消息");
                return message;
            }
        });
        System.out.println("发送成功");
    }
}
